package org.example.service.impl;

import org.example.mapper.BookMarksMapper;
import org.example.mapper.TagsMapper;
import org.example.pojo.BookMarks;
import org.example.pojo.Tags;
import org.example.service.TagsService;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class TagsServiceImpl implements TagsService {
    @Autowired
    private TagsMapper tagsMapper;
    @Autowired
    private BookMarksMapper bookMarksMapper;
    @Override
    public List<Tags> tagsList(Tags tags) {
        return tagsMapper.tagsList(tags);
    }

    @Override
    public void addTag(Tags tags) {
        tagsMapper.addTag(tags);
    }

    @Override
    public Result delTag(Tags tags) {
        // 根据标签id查询是否存在书签
        List<BookMarks> bookMarks = bookMarksMapper.bookMarksList(tags.getUserId(), null, null, null, tags.getId(), null, null);
        if(!bookMarks.isEmpty()) {
            return Result.error("当前标签下存在书签，无法删除");
        }
        tagsMapper.delTag(tags.getId());
        return Result.success();
    }

    @Override
    public void editTag(Tags tags) {
        tagsMapper.editTag(tags);
    }
}
